package com.wkbb.common.utils;

import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author luowenyan
 * @version V1.0
 * @className ObjectUtil
 * @description TODO
 * @date 2019/10/21 12:33
 */
public class ObjectUtil {

    private static final Logger logger = LoggerFactory.getLogger(ObjectUtil.class);

    public static List<Object[]> trans(List<Object> excelData,Integer columns){
        List<Object[]> data = new ArrayList<Object[]>();
        for (Object objects : excelData) {
            Map map = (Map<String,Object>)objects;//JSON.parseObject(JSONObject.toJSONString(objects));
            Object[] object = new Object[columns];
            for (int i = 0; i < columns; i++) {
                Object oriObject = map.get(i);
                if(oriObject==null)
                {
                    oriObject = "";
                }
                else
                {
                    oriObject = oriObject.toString().trim();
                }
                object[i] = oriObject;
            }
            data.add(object);
        }
        for (Object[] objects : data) {
            logger.info(JSONObject.toJSONString(objects));
        }
        return data;
    }

    public  static Object getObject(Object object){
        return object==null?"":object;
    }
}
